package com.st.event.demo.strategy;

import com.st.event.demo.source.EventAttribute;
import com.st.event.demo.strategy.builder.HandlerFactoryBuilder;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

public abstract class AbstractEventStrategy implements EventStrategy {

    private HandlerFactoryBuilder factoryBuilder;

    private List<StrategyHandler> strategyHandlers = new ArrayList<>();

    public AbstractEventStrategy(HandlerFactoryBuilder factoryBuilder, List<StrategyHandler> strategyHandlers) {
        this.factoryBuilder = factoryBuilder;
        this.strategyHandlers = strategyHandlers;
    }

    @Override
    public StrategyHandler getHandler(EventAttribute eventAttribute) {
        StrategyFactory factory = factoryBuilder.build(strategyHandlers);
        return factory.canApply(eventAttribute);
    }

    @Override
    public Object wrap(Class<?> clientInterface, Method method, Object arg) {
        return arg;
    }
}
